<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>用户管理</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/backStyle.css">
<link rel="stylesheet" type="text/css" href="css/myButton.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap-modal.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>

<style>
html,body {
	height: 100%;
	width: 100%;
	border: 0;
	background: #fff;
	overflow-y: auto;
}
</style>
</head>

<body>
	<ul class="breadcrumb">
		<li><a href="sys/welcome.jsp">首页</a></li>
		<li class="active">用户管理</li>
	</ul>
	<div class="panel panel-default">
		<div class="panel-body">
			<table class="table table-striped">
				<thead>
					<tr>
						<th>ID</th>
						<th>用户名</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="userTable">

				</tbody>
			</table>
		</div>
	</div>
</body>
<script type="text/javascript">
		function modifyUser(id){
			window.location.href="<%=basePath%>userManageView.action?user.id="+id;
		}
		
		function setUserIsDelete(id,operation,isDelete){
			if(!confirm("您确定要"+operation+"此账号么？")){
				return false;
			}
			$.ajax({
				url : "setUserIsDelete.action",
				type : "post",
				data:{"user.id" : id,
					"user.isDelete":isDelete
				},
				dataType : "json",
				success : function(data) {
					var flag = JSON.parse(data).flag;
					if(flag == "success") {
						alert("账号"+operation+"成功！");
						window.location.reload();
					}
					if(flag == "error") {
						alert("账号"+operation+"失败！");
					}
				},
				error : function() {
					alert("与服务器同步失败！");
				}
			});
		}
		
		$(document).ready(function(){
			$.ajax({
				type:'post',
				url: "getAllUsers.action",
				data:{},
				dataType: "json",
				success: function(data){
					var list = eval(data);
					var htmlstr = "";
					if(list.length > 0){
						for(var i=0;i<list.length;i++){
							htmlstr += "<tr>";
							htmlstr += "<td>"+list[i].id+"</td>";
							htmlstr += "<td>"+list[i].username+"</td>";
							htmlstr += "<td><a class=\"button blue medium\" onclick=\"modifyUser("+list[i].id+")\">修改</a>";
							if(list[i].isDelete == 0) {
								htmlstr += "<a class=\"button rosy medium\" onclick=\"setUserIsDelete('"+list[i].id+"','封禁','1')\">封禁</a></td>";
							} else {
								htmlstr += "<a class=\"button rosy medium\" onclick=\"setUserIsDelete('"+list[i].id+"','解封','0')\">解封</a></td>";
							}
							htmlstr += "</tr>";
						}
						$("#userTable").html(htmlstr);
					}
				}
			});
		})
</script>
</html>
